<template>
  <nav-bar>
    <template #left>
      <icon name="wap-nav" size="0.52rem"/>
    </template>
    <template #title>
      <div class="nav-center">
        <span 
          class="nav-text" 
          v-for="(nav, i) in navBarList" 
          :key="i" 
          :class="{'nav-active': i === activeIndex}"
          @click="navClick(i)"
        >{{ nav }}</span>
      </div>
    </template>
    <template #right>
      <icon name="search" size="0.52rem"/>
    </template>
  </nav-bar>
</template>

<script lang="ts">
import { defineComponent, ref ,Ref, reactive } from 'vue';
import { Icon, NavBar } from 'vant'
export default defineComponent({
  name: 'HeaderNav',
  components: {
    Icon,
    NavBar
  },
  setup() {
    const activeIndex:Ref = ref(1)
    const navBarList = reactive(['我的', '发现', '云村', '视频'])
    
    function navClick(index: number) {
      activeIndex.value = index
    }
    return {
      activeIndex,
      navBarList,
      navClick
    }
  },
});
</script>

<style lang="less" scoped>
.van-icon {
  color: #5A6585 !important;
}
.nav-center {
  width: 5rem;
  padding: 0 .16rem;
  display: flex;
  justify-content: space-evenly;
  font-size: .32rem;
  .nav-text {
    color: #939CB6;
  }
  .nav-active {
    font-weight: 900;
    color: #202D40;
  }
}

</style>